package com.koron.system.company.mapper;

import com.koron.system.company.pojo.po.CompanyPO;
import com.koron.system.company.pojo.query.CompanyQuery;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CompanyMapper {


    @Select({
            "<script>",
            "select * from w_company_info where 1=1",
            "<if test='id!= null and id!= \"\"'>",
            "and id = #{id}",
            "</if>",
            "<if test='comCd!= null and comCd.trim()!= \"\"'>",
            "and com_cd = #{comCd}",
            "</if>",
            "<if test='comNm!= null and comNm.trim()!= \"\"'>",
            "and com_nm like concat('%',#{comNm},'%')",
            "</if>",
            "</script>"
    })
    List<CompanyPO> list(CompanyQuery companyQuery);

    @Insert({
            "insert into w_company_info(com_cd, com_nm, com_full_nm,com_cw_cd,lp_nm, lp_phone,lp_tel,contact_nm,contact_phone,contact_tel,location)",
            "values (#{comCd},#{comNm},#{comFullNm},#{comCwCd},#{lpNm},#{lpPhone},#{lpTel},#{contactNm},#{contactPhone},#{contactTel},#{location})",
            "on duplicate key update com_nm = #{comNm}, com_full_nm = #{comFullNm}, com_cw_cd = #{comCwCd},lp_nm = #{lpNm}, lp_phone = #{lpPhone},lp_tel = #{lpTel},contact_nm = #{contactNm},contact_phone = #{contactPhone},contact_tel = #{contactTel},location = #{location}"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(CompanyPO companyPO);

    @Delete("update w_company_info set delete_flag = 1 where id = #{id}")
    int delete(Integer id);
}
